import {defineStore} from "pinia";
import { computed, ref } from "vue";



export const useUserStore = defineStore("user", () => {
    //定义state -需要分享的数据都要定义为state
    const user = ref(null);

    //定义getter
    const userInfo = computed(() => {
        return user.value;
    });
    //定义action-修改state
    function update(u) {
        user.value = u;
    }

    //重置state
    function $reset() {
        user.value = null;
    }

    return { user, userInfo, update, $reset };
}, {
    persist: {
        key: 'user',
        storage: sessionStorage,
        paths: ['user']
    }
});